let newApp = function (app) {
    this.appp = app
    this.routeTree = []
}
newApp.prototype.use = function (...argument) {
    let rootroute = {
        descri: (val) => {
            rootroute.content = val
        }
    }
    if (Object.prototype.toString.call(argument[0]).indexOf('String') >= 0) {
        Object.assign(rootroute, {
            path: argument[0],
            content: '',
            // route: route,
            children: []
        })

    }
    else {
        Object.assign(rootroute, {
            path: '/',
            content: '',
            children: []
        })

    }
    // let route = argument[argument.length - 1]

    // if (route.stack.length > 0) {

    //     let childroute = route.stack.map(row => ({
    //         path: row.route.path,
    //         content: '',
    //         // route: row,
    //         method: row.route.stack[0].method
    //     }))
    //     rootroute.children.push(...childroute)
    // }


    let _newargument = []
    let _childrenroute
    for (let i = 0; i < argument.length; i++) {
        if (argument[i]._router) {
            _childrenroute = argument[i].routerArry
            _newargument.push(argument[i]._router)
        }
        else
            _newargument.push(argument[i])
    }
    rootroute.children.push(..._childrenroute)

    this.routeTree.push(rootroute)

    this.appp.use(..._newargument);
    return rootroute
}


module.exports = {
    newApp
};